<template>
	<view class="signin">
		<view class="title"><image class="title-img" src="../../static/title.png"></image></view>
		<view class="bg"><image class="bg-img" src="../../static/bg.png"></image></view>
		<view class="box">
			<view class="box-title">
				<image class="bt-img" src="../../static/tit.png"></image>
				<view class="bt-tit">
					<text>·</text>
					<text>活动信息</text>
					<text>·</text>
				</view>
			</view>
			<image class="bgc-img right" src="../../static/bgi1.png"></image>
			<image class="bgc-img left" src="../../static/bgi2.png"></image>
			<view class="content">
				<view class="cont-title">
					<view class="text_box">
						<view class="bgc"></view>
						<view class="text">活动主题</view>
					</view>
				</view>
				<view class="ct-cont u-line-2">{{ detail.name }}</view>
				<view class="cont-title">
					<view class="text_box">
						<view class="bgc"></view>
						<view class="text">活动内容</view>
					</view>
				</view>

				<view class="ct-cont cont_desc">{{ parameter.summary }}</view>
				<!-- <view class="cont-title">
					<view class="text_box">
						<view class="bgc"></view>
						<view class="text">报名信息</view>
					</view>
				</view> -->
				<!-- 				<view class="detail-box">
					<text style="padding-bottom: 20rpx;">姓名：王思聪</text>
					<text>电话：15779760254</text>
				</view> -->
				<view :class="['btn', signStr ? 'no_btn' : '']" @click="clickSign">立即签到</view>
				<view class="time_box" v-if="parameter.form">
					<view class="sign_time" v-if="parameter.form.signDate && parameter.form.signTime">
						<view>{{ parameter.form.signDate | formTime() }}</view>
						<view style="margin-left: 10rpx;">{{ parameter.form.signTime | timeSlot()}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { formatDate } from '@/utils/moment/index.js';
export default {
	data() {
		return {
			detail: {},
			parameter: {},
			signStr: '' // 是否不满足签到要求
		};
	},
	onLoad() {
		let pages = getCurrentPages();
		let current = pages[pages.length - 2]; // 上个页面
		if (current.$vm.detail) {
			this.detail = {
				...current.$vm.detail,
				options: JSON.parse(current.$vm.detail.option_val)
			};
			this.parameter = JSON.parse(current.$vm.detail.parameter);
			this.stateJudge();
		}
	},
	filters: {
		formTime(val) {
			return formatDate(new Date(val), 'YYYY-MM-DD');
		},
		timeSlot (str) {
			let arr = str.split(',')
			return arr[0] + ' ~ ' + arr[1]
		}
	},
	methods: {
		stateJudge() {
			if (this.parameter.form.signDate && this.parameter.form.signTime) {
				let nowDate = new Date();
				let arr1 = formatDate(new Date(this.parameter.form.signDate), 'YYYY-MM-DD').split('-');
				let nowArr = formatDate(new Date(), 'YYYY-MM-DD').split('-');
				if (arr1[0] == nowArr[0] && arr1[1] == nowArr[1] && arr1[2] == nowArr[2]) {
					this.signStr = this.checkxs();
				} else {
					this.signStr = '不在签到时间内';
				}
			}
		},
		// 检测签到时间段
		checkxs() {
			let objtime = new Date();
			let asletime = this.parameter.form.signTime.split(',');
			let currenttime = objtime.getHours() * 60 + objtime.getMinutes();
			let starttime = Number(asletime[0].split(':')[0]) * 60 + Number(asletime[0].split(':')[1]);
			let endttime = Number(asletime[1].split(':')[0]) * 60 + Number(asletime[1].split(':')[1]);
			if (starttime > currenttime || currenttime > endttime) {
				return '不在签到时间内';
			} else {
				return '';
			}
		},
		clickSign() {
			if (this.signStr) {
				return;
			}
			this.$loading();
			let time = formatDate(new Date(), 'YYYY-MM-DD HH:mm');

			let params = {
				pk_id: this.detail.fk_custom_form_id,
				time: time
			};
			this.$resPost('GetCustomFormValInfo', params).then(res => {
				this.dataForm = res.data;
				this.$linkTo(`/package/activity/form/SignIn/Successful/index?formId=${this.detail.fk_custom_form_id}`, 'redirectTo');
				this.$hide();
			});
		}
	}
};
</script>
<style>
page {
	background-color: #f5f5f5;
}
</style>
<style lang="scss" scoped>
.signin {
	background-image: url();
	background-repeat: no-repeat;
	background-size: 100% 440rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	position: relative;
	.bg {
		position: absolute;
		top: 194rpx;
		right: 0;

		.bg-img {
			width: 156rpx;
			height: 136rpx;
		}
	}

	.title {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		padding-top: 60rpx;

		.title-img {
			width: 360rpx;
			height: 200rpx;
		}
	}
	.box {
		margin-top: 10rpx;
		width: 670rpx;
		height: 1030rpx;
		background-image: url();
		background-repeat: no-repeat;
		background-size: 100%;
		position: relative;
		margin-bottom: 100rpx;
		.bgc-img {
			width: 72rpx;
			height: 16rpx;
			position: absolute;
		}

		.left {
			left: 120rpx;
			top: 110rpx;
		}

		.right {
			top: 60rpx;
			right: 110rpx;
		}

		.box-title {
			margin: 0 auto;
			width: 332rpx;
			height: 70rpx;
			position: relative;
			margin-top: 50rpx;

			.bt-img {
				width: 100%;
				height: 100%;
			}

			.bt-tit {
				position: absolute;
				display: flex;
				align-items: center;
				justify-content: center;
				top: 8rpx;
				left: 72rpx;
				font-size: 40rpx;
				font-weight: bold;
				color: #f3503f;
			}
		}

		.content {
			padding: 0 46rpx 0 30rpx;

			.cont-title {
				display: flex;
				padding-top: 34rpx;
				.text_box {
					font-size: 32rpx;
					font-weight: bold;
					color: #000;
					line-height: 60rpx;
					position: relative;
					.text {
						position: relative;
						z-index: 10;
					}
					.bgc {
						background-color: #ffdccf;
						width: 100%;
						height: 6rpx;
						position: absolute;
						bottom: 6rpx;
						left: 0;
						width: 100%;
					}
				}
			}

			.ct-cont {
				font-size: 28rpx;
				color: #333;
				padding-top: 20rpx;
				&.cont_desc {
					white-space:pre-wrap;
				}
			}

			.detail-box {
				width: 100%;
				height: 166rpx;
				background-color: #f2f2f2;
				display: flex;
				justify-content: center;
				flex-direction: column;
				font-size: 30rpx;
				color: #333;
				padding-left: 24rpx;
				margin-top: 20rpx;
				font-weight: bold;
				margin-bottom: 80rpx;
			}
			.btn {
				width: 500rpx;
				height: 90rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background-color: #d82537;
				color: #fff;
				font-size: 46rpx;
				font-weight: bold;
				border-radius: 12rpx;
				margin: 70rpx auto 0;
				&.no_btn {
					background-color: #ddd;
				}
			}
		}
		.time_box {
			margin-top: 16rpx;
			.sign_time {
				justify-content: center;
				display: flex;
				color: #999;
				margin-bottom: 6rpx;
				font-size: 26rpx;
				.flex_sign {
					flex: 1;
					overflow: hidden;
				}
			}
		}
	}
}
</style>
